<?php

namespace App\Console\Commands;

use App\App\Services\SyncCacheService;
use Illuminate\Console\Command;
use Carbon\Carbon;

class Storage extends Command
{
    protected $syncCacheService;
    protected $lock;
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'storage';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '把Redis列表中的投票记录写入数据库';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct(SyncCacheService $syncCacheService)
    {
        $this->syncCacheService = $syncCacheService;
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        echo "把投票数据写入数据库" . PHP_EOL;
        echo "开始" . PHP_EOL;
        $this->syncCacheService->storageVoteLogs();
        echo Carbon::now()->format('Y-m-d H:i:s') . PHP_EOL;
        echo "完成" . PHP_EOL;
    }
}
